/*
IM的日志接口。IM模块内部，只提供日志的记录调用路径，不记录日志，日志的记录工作，由外部调用模块通过绑定事件实现；


日期          作者           说明
----------------------------------------
2018-08-29    lcl           源代码 ver 1.0
+
*/
package com.example.tang5.myapplication.im.IMLoger;

import java.util.Date;


//IMLoger IM2的日志对象，以单例实现。
public class IMLoger {
	//单例
	private static IMLoger inst;

	public static IMLoger instance() {
		if (null == inst) {
			inst = new IMLoger();
		}
		return inst;
	}

	//日志类型常量
	public static final Integer LOG_TYPE_DEBUG = 0; //调试
	public static final Integer LOG_TYPE_INFO = 1; //普通信息
	public static final Integer LOG_TYPE_WARNNING = 2; //警告
	public static final Integer LOG_TYPE_EXCEPTION = 3; //异常
	public static final Integer LOG_TYPE_ERROR = 4; //错误

	//日志写入接口
	private LogWriter logWriter = null;

	//绑定日志写入接口
	public void setLogWriter(LogWriter writer) {
		this.logWriter = writer;
	}

	//addLog，调用日志写入接口，以实现IM2的日志信息输出到外部系统
	public void addLog(Integer logType, Date date, String logFrom, String logText, String environment) {
		try {
			if (logWriter != null) {
				logWriter.write(logType, date, logFrom, logText, environment);
			}
		} catch (Exception e) {
			//为了避免外部的日志写入代码发生异常，造成IM2模块问题，加入异常捕获，但是此处什么也不做；
		}
	}

	//addDebug 添加一条“调试”日志
	public void addDebug(int Type, Date date, String logFrom, String logText, String environment) {
		this.addDebug(LOG_TYPE_DEBUG, date, logFrom, logText, environment);
	}

	//addInfo 添加一条“普通”日志
	public void addInfo(Date date, String logFrom, String logText, String environment) {
		this.addDebug(LOG_TYPE_INFO, date, logFrom, logText, environment);
	}

	//addWarnning 添加一条“警告”日志
	public void addWarnning(Date date, String logFrom, String logText, String environment) {
		this.addDebug(LOG_TYPE_WARNNING, date, logFrom, logText, environment);
	}

	//addException 添加一条“异常”日志
	public void addException(Date date, String logFrom, String logText, String environment) {
		this.addDebug(LOG_TYPE_EXCEPTION, date, logFrom, logText, environment);
	}

	//addError 添加一条“错误”日志
	public void addError(Date date, String logFrom, String logText, String environment) {
		this.addDebug(LOG_TYPE_ERROR, date, logFrom, logText, environment);
	}


}